<template>
  <BaseForm v-model="formDataModel" @close="$emit('callBack')" />

</template>

<script lang="ts" setup>
import type { FormInstance } from 'element-plus'
import StoreInfoInspectionRecordsApi from '/@/api//StoreInfoInspectionRecordsApi.ts';
import { translate } from "/@/i18n";
import FORM_FIELD_TYPE from "/@/constants/FormFieldType.ts";
defineOptions({
  name: 'StoreInfoInspectionRecordsEdit',
})
const props = defineProps({
  modelValue: {

  }
})
const emit = defineEmits(['fetch-data', 'callBack'])

const formRef = ref<FormInstance>();
const title = ref<string>('');
const dialogFormVisible = ref<boolean>(false);



const formDataModel = ref({
  columnCount: 1,
  expandLimit: 6,
  autoFit: false,
  columnWidth: '200px',
  labelPosition: 'left',
  labelWidth: '300px',
  modelData: {},  //表单参数值 初始化
  callback: async (any: object) => {  //表单执行成功后回调
    //完成数据提交
    const { message } = await StoreInfoInspectionRecordsApi.save(any)
    $baseMessage(message, 'success', 'vab-hey-message-success');
    dialogFormVisible.value = false


    //事件及数据推送到上一层父类
    emit('callBack', any); //把表单数据推送到上一层
  },
  items: [  //表单item数据初始化
    {
      label: "入库日期",
      field: "enterDate",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

      config: {
        props: {   //日期精度配置
          type: "daterange",
          startPlaceholder: "开始日期",
          endPlaceholder: "结束日期",
          format: "YYYY-MM-DD",
        },
        disabled: true,
      },
    },
    //   {
    //     label: "物料ID",
    //     field: "materialId",
    //     clearable: true,
    //     type: FORM_FIELD_TYPE.INPUT,

    //    placeholder:"请输入",

    //    rule:{
    //      trigger: 'blur',
    //      validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //            callback();
    //        },
    //      },

    // },
    {
      label: "物料编码",
      field: "materialCode",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      config: {
        disabled: true
      },

    },
    {
      label: "物料名称",
      field: "materialName",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      config: {
        disabled: true
      },
    },
    {
      label: "规格",
      field: "materialSpc",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      config: {
        disabled: true
      },

    },

    {
      label: "生产日期",
      field: "produceDate",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

      config: {
        props: {   //日期精度配置
          type: "daterange",
          startPlaceholder: "开始日期",
          endPlaceholder: "结束日期",
          format: "YYYY-MM-DD",
        },
        disabled: true,
      },
    },
    {
      label: "质保期",
      field: "warrantyPeriod",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      config: {
        disabled: true
      },

    },
    //   {
    //     label: "供应商ID",
    //     field: "supplierId",
    //     clearable: true,
    //     type: FORM_FIELD_TYPE.INPUT,

    //    placeholder:"请输入",

    //    rule:{
    //      trigger: 'blur',
    //      validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //            callback();
    //        },
    //      },

    // },
    {
      label: "供应商名称",
      field: "supplierName",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      config: {
        disabled: true
      },
    },
    {
      label: "供应商地址",
      field: "supplierAdd",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      config: {
        disabled: true
      },
    },
    {
      label: "入库批次",
      field: "batchNo",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      config: {
        disabled: true
      },
    },
    {
      label: "入库数量",
      field: "num",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,
      placeholder: "请输入",
      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      config: {
        disabled: true
      },
    },
    {
      label: "营业执照和食品经营/生产许可证",
      field: "isCertificate",
      clearable: true,
      type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,

      placeholder: "请输入",
      options: [
        {
          value: '无',
          label: "无"
        },
        {
          value: '有',
          label: "有"
        },
        {
          value: '不适用',
          label: "不适用"
        }
      ],
      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },

    {
      label: "购货凭证",
      field: "isVoucher",
      clearable: true,
      type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
      options: [
        {
          value: '无',
          label: "无"
        },
        {
          value: '有',
          label: "有"
        },
        {
          value: '不适用',
          label: "不适用"
        }
      ],
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    {
      label: "动物检疫合格证明",
      field: "isQuarantine",
      clearable: true,
      type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
      options: [
        {
          value: '无',
          label: "无"
        },
        {
          value: '有',
          label: "有"
        },
        {
          value: '不适用',
          label: "不适用"
        }
      ],
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    {
      label: "肉品品质检验合格证",
      field: "isQualityCertificate",
      clearable: true,
      type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
      options: [
        {
          value: '无',
          label: "无"
        },
        {
          value: '有',
          label: "有"
        },
        {
          value: '不适用',
          label: "不适用"
        }
      ],
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    {
      label: "该批产品检测报告（出厂检验报告、农残检测报告）",
      field: "isQualityReport",
      clearable: true,
      type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
      options: [
        {
          value: '无',
          label: "无"
        },
        {
          value: '有',
          label: "有"
        },
        {
          value: '不适用',
          label: "不适用"
        }
      ],
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    {
      label: "合格证",
      field: "isPass",
      clearable: true,
      type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
      options: [
        {
          value: '无',
          label: "无"
        },
        {
          value: '有',
          label: "有"
        },
        {
          value: '不适用',
          label: "不适用"
        }
      ],
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    {
      label: "外观检查",
      field: "isAppearance",
      clearable: true,
      type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
      options: [
        {
          value: '符合',
          label: "符合"
        },
        {
          value: '不符合',
          label: "不符合"
        },
        {
          value: '不适用',
          label: "不适用"
        }
      ],
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    {
      label: "温度检查",
      field: "isTemperature",
      clearable: true,
      type: FORM_FIELD_TYPE.SINGLE_LAYER_SELECT,
      options: [
        {
          value: '符合',
          label: "符合"
        },
        {
          value: '不符合',
          label: "不符合"
        },
        {
          value: '不适用',
          label: "不适用"
        }
      ],
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

    },
    // {
    //   label: "检测报告",
    //   field: "reportUrl",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,
    //   config: {
    //     type: "file",
    //     disabled: true,
    //   },
    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    //   // 添加一个条件判断，如果 reportUrl 有值，则显示该项，否则隐藏  【修改处1】
    //   show: (model: any) => {
    //     return model.reportUrl != '' && model.reportUrl !== null;
    //   }
    // },
    {
      label: "样品名称",
      field: "sampleName",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,

      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },
      config: {
        disabled: true
      },

    },
    // {
    //   label: "样品批次",
    //   field: "sampleBatch",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },
    // },
    {
      label: "报告日期",
      field: "sampleDate",
      clearable: true,
      type: FORM_FIELD_TYPE.INPUT,
      placeholder: "请输入",

      rule: {
        trigger: 'blur',
        validator: (rule: any, value: any, callback: any) => {  //绑定验证
          callback();
        },
      },

      config: {
        disabled: true,
        props: {   //日期精度配置
          type: "daterange",
          startPlaceholder: "开始日期",
          endPlaceholder: "结束日期",
          format: "YYYY-MM-DD",
        },

      },

    },
    {
      label: "上传凭证",
      field: "sampleUrl",
      clearable: true,
      type: FORM_FIELD_TYPE.UPLOAD,
      config: {
        limit: 10
      },
      placeholder: "请输入",
      rule: {
        trigger: 'blur',
      },
    },
    // {
    //   label: "报告链接",
    //   field: "sampleUrl",
    //   clearable: true,
    //   type: FORM_FIELD_TYPE.INPUT,

    //   placeholder: "请输入",

    //   rule: {
    //     trigger: 'blur',
    //     validator: (rule: any, value: any, callback: any) => {  //绑定验证
    //       callback();
    //     },
    //   },

    // },

  ],
})






//页面数据加载
onMounted(async () => {

  //初始化数据model
  if (props.modelValue.query) { //跳转过来时候有参数
    if (props.modelValue.query.storeInfoInspectionRecordsId) {  //id存在则为编辑，加载网络数据，如上级页面带参数手动覆盖

      const { data } = await StoreInfoInspectionRecordsApi.getDetail({
        storeInfoInspectionRecordsId: props.modelValue.query.storeInfoInspectionRecordsId   //从路由中获取参数
      })
      formDataModel.value.modelData = data;
    } else {
      //新增时候则用父类页面传参默认填充可根据业务修改
      for (const key in props.modelValue.query) {
        formDataModel.value.modelData[key] = props.modelValue.query[key]
      }
    }
  }
})


//方法暴露区域  todo
defineExpose({

})

</script>
